const topicModel = require('../models/topic.js')

exports.list = async (req, res, next) => {
	try {
		const topics = await topicModel.getTopics(req.query)
		res.status(200).json(topics)
	} catch(err) {
		next(err)
	}
}

exports.create = async (req, res, next) => {
	try {
		let body = req.body
		body.user_id = req.session.user.id
		const id = await topicModel.addTopic(body)
		const topic = await topicModel.getTopic(id)
		res.status(201).json(topic)
	} catch(err) {
		next(err)
	}
}

exports.modify = async (req, res, next) => {

}

exports.destroy = async (req, res, next) => {

}
